<?php
class AjaxModel extends Model {
	
	/**
	 * Find leksems by name
	 * 
	 * @param $leksName string
	 * @param $websiteId integer
	 * @return array
	 */
	public function findLeks($leksName, $websiteId) {
		$leks = array();
		$queryString = "
			SELECT 
				`leks`.`id`
			FROM
				`leks`
			WHERE
				`leks`.`name` LIKE '%$leksName%'
			AND
				`leks`.`id_website` = $websiteId 
			ORDER BY `id` DESC
		";
		$result = $this->_sqlInstance->query($queryString);
		foreach ($result as $row) {
			$leks[] = new Leksem($row->id); 
		}
		return $leks;
	}
	
	/**
	 * Find leksems by original value
	 * 
	 * @param $leksValue string
	 * @param $websiteId integer
	 * @return array
	 */
	public function findLeksByVal($leksValue, $websiteId) {
		$leks = array();
		$queryString = "
			SELECT 
				`leks`.`id`
			FROM
				`leks`
			JOIN
				`base`
			ON
				`leks`.`id` = `base`.`id_leks`
			WHERE
				`base`.`value` LIKE '%$leksValue%'
			AND
				`leks`.`id_website` = $websiteId 
			ORDER BY `id` DESC 
				
		";
		$result = $this->_sqlInstance->query($queryString);
		foreach ($result as $row) {
			$leks[] = new Leksem($row->id); 
		}
		return $leks;
	}
}
